/*
 * @Author: your name
 * @Date: 2021-08-25 09:52:04
 * @LastEditTime: 2021-09-09 20:29:56
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \musicapp\src\router\index.js
 */
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store/index.js'

const routes = [{
        path: '/',
        name: 'Home',
        component: Home
    },
    {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/About.vue')
    },
    {
        path: '/listview',
        name: 'listview',
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/ListView.vue')
    },
    {
        path: '/search',
        name: 'search',
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/Search.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/Login.vue')
    },
    {
        path: '/me',
        name: 'me',
        beforeEnter: (to, from, next) => {
            console.log(store.state.user);
            if (store.state.user.isLogin) {
                next()
            } else {
                next('/login')
            }

        },
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/Me.vue')
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

export default router